All Questions
61 questions
1vote
0answers
313views
Implementing a memory efficient Abstract Syntax Tree
I am writing a compiler in C++ 20. I am looking for ways to improve heap memory performance. For example, I can compile a 36.8 MB source file that is just many repeating lines of: let x0: string = &...
15votes
6answers
6kviews
Why is it necessary to mark classes as not inherited from? Can't an optimizer automatically detect that virtual calls are unnecessary?
In C# and C++, an apparent trend is in place to reduce / avoid inheritance: C#: "Sealing types can improve performance." https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/...
0votes
1answer
787views
Custom #pragma directives
I'm creating a language parser on a microprocessor in C++. For the tables of keywords and commands, rather than maintaining a single curated file (alphabetically sorted, etc), I'd prefer to declare ...
4votes
1answer
4kviews
In C++, If a member function can be made static with no change to functionality, are there any performance or memory benefits from doing so?
A very straightforward question. When I think about many of the member functions I create for my classes, many of them can be made static without affecting any functionality whatsoever. If I do so; ...
-2votes
1answer
488views
Which non-standard C features can I use? [closed]
C and C++ have standards, but support isn't perfect, the only available copies on the internet are drafts, and there are immensely useful things that aren't standard, such as __attribute__((cleanup)). ...
1vote
2answers
1kviews
Template argument type exclusion: Would this make for a useful C++ feature?
When using templates we can have T be any type upon class instantiation. If T is a specific type that needs to be handled differently or in a special way we can specialize or partial specialize that ...
2votes
4answers
873views
C++ - Is it bad practice to use compiler specific functions?
My requirement is simple, I want to be able to count the number of bits in a number. With a little bit of research, I found that MSVC has __popcnt, GCC has __builtin_popcount and so on. At this stage,...
0votes
2answers
2kviews
Why are some languages called platform dependent if I can always share the source code?
I was reading about erlang when I read that it is platform-independent, using BEAM as the VM, now I understand that a VM compiles the byte code to machine code and this makes that language machine-...
2votes
4answers
239views
A language design with variable qualifier
I am planning to design a programming language. One challenge I face with is whether it is a good idea to have const as a variable qualifier instead of a type qualifier. For example in C++: const int ...
1vote
2answers
6kviews
Will compiled python code be as fast as compiled C++ code?
I know that Python is an interpreted language and that c++ is a compiled one, or at least I like to think that I've understood some of their differences. Although C++ is apparently faster than ...
5votes
1answer
2kviews
C++ design pattern for template instantiation based on run time information?
Say I want to be able to create objects for a range of template parameter template<int a> class Myclass : public MyclassSuper{...}; And I want to create objects like Myclass<...
7votes
2answers
8kviews
What is the difference between a static library and an archive library?
In the comments of a recent answer, I equated a static library with an archive of compiled object files. The response was that they are not the same, so what is the difference? To clarify - gcc ...
2votes
3answers
558views
In c++, is there a way inside a function block, to execute cleanup code after the value has been returned?
Backstory (You can skip) I am building an API for managing Files and Directories in a consistent manner across a project. This is for deduplication and consistency when performing a task, and in this ...
0votes
4answers
1kviews
Is it better to use the linker to compile multiple C++ files or better to include them as a header file
Assume we have two files a.cc #include <iostream> int timesTwo(int in); int main(){ std::cout << timesTwo(5) << std::endl; return 0; } b.cc int timesTwo(int in){ return in*2; ...
0votes
1answer
126views
Is there a way to use and ignore blocks of code, caused by events during runtime?
I'm working in C++14 and trying to figure out a way to put two classes (with the same name) inside the same header file. In this scenario one class would always be ignored as a result of something ...